package landlords.client.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import landlords.client.event.ClientEventListener;
import landlords.entity.ClientTransferData;
import landlords.enums.ClientEventCode;
import landlords.print.SimplePrinter;

public class ProtobufTransferHandler extends ChannelInboundHandlerAdapter {
    public void channelRead(ChannelHandlerContext ctx, Object msg){
        ClientTransferData.ClientTransferDataProtoc clientTransferData=(ClientTransferData.ClientTransferDataProtoc)msg;
        if(!clientTransferData.getInfo().isEmpty()){
            SimplePrinter.printNotice(clientTransferData.getInfo());
        }
        //获取服务器端传过来的代码code值
        ClientEventCode code=ClientEventCode.valueOf(clientTransferData.getCode());
        //根据传过来的code值调取相应的对象及方法
        ClientEventListener.get(code).call(ctx.channel(),clientTransferData.getData());

    }
}
